package atom.core0.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;



/**
 * 连接池管理器
 */
public class JndiManager {
	/*
	 * 返回短信平台的数据库连接
	 * 
	 */
	private static DataSource ds = null;

	
	//jdbc/fmmsdb
	public static Connection getConnection(String jndi) {
		Connection conn = null;
		try {
			if( ds == null )
			{
				Context ctx = new InitialContext();
				ds = (DataSource) ctx.lookup(jndi);
			}
		    conn = ds.getConnection();
		    conn.setAutoCommit(false);
		}catch(Exception e) {
			try {conn.close();} catch(Exception ignore) {}
			conn = null;
			System.out.println("获取数据库连接异常");
		}
		return conn;
	}
	

}
